﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ListaOrigen.Items.Add(new ListItem("Rojo", "1"));
            ListaOrigen.Items.Add(new ListItem("Azul", "2"));
            ListaOrigen.Items.Add(new ListItem("Verde", "3"));
            ListaOrigen.Items.Add(new ListItem("Blanco", "4"));
            ListaOrigen.Items.Add(new ListItem("Negro", "5"));
        }

    }
    protected void btn_AgregarUnoDestino_Click(object sender, EventArgs e)
    {
        if (ListaOrigen.SelectedItem != null)
        {
            int i = ListaDestino.Items.Count + 1;
            string n = ListaOrigen.SelectedItem.ToString();
            ListaDestino.Items.Add(new ListItem("" + n, "" + i));
            ListaOrigen.Items.RemoveAt(ListaOrigen.SelectedIndex);
        }
    }
    protected void btn_AgregarTodosDestino_Click(object sender, EventArgs e)
    {
        foreach (ListItem item in ListaOrigen.Items)
        {
            ListaDestino.Items.Add(item);
        }

        ListaOrigen.Items.Clear();
    }
    protected void btn_aceptar_Click(object sender, EventArgs e)
    {
        string mostrar = "";
        if (ListaDestino.Items.Count == 0)
        {
            mostrar = "No hay colores seleccionados";
        }
        else
        {
            mostrar = "Los colores son: ";
            int cantidad = ListaDestino.Items.Count - 1;

            for (int i = 0; i < ListaDestino.Items.Count; i++)
            {
                if (i == cantidad)
                {
                    mostrar += "" + (ListaDestino.Items[i].ToString() + ". ");
                }
                else
                {
                    mostrar += "" + (ListaDestino.Items[i].ToString() + ", ");
                }
            }   
        } 

        lbl_ColoresSeleccionados.Text = mostrar;
    }

    protected void btn_EliminarTodosDestino_Click(object sender, EventArgs e)
    {
        foreach (ListItem item in ListaDestino.Items)
        {
            ListaOrigen.Items.Add(item);
        }

        ListaDestino.Items.Clear();
    }
    protected void btn_EliminarUnoDestino_Click(object sender, EventArgs e)
    {
        if (ListaDestino.SelectedItem != null)
        {
            int i = ListaOrigen.Items.Count + 1;
            string n = ListaDestino.SelectedItem.ToString();
            ListaOrigen.Items.Add(new ListItem("" + n, "" + i));
            ListaDestino.Items.RemoveAt(ListaDestino.SelectedIndex);
        }
    }
}
